package com.yuyou.fn.timer.task;

import com.github.wens.mybatisplus.examples.Example;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.common.util.Utils;
import com.yuyou.fn.educational.entity.CourseClass;
import com.yuyou.fn.educational.service.ICourseClassService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 更新课程表同步mogodb数据
 * Created by wens on 2017/4/19.
 */
@JobHander(value="UpdateCourseClassTask")
@Component
public class UpdateCourseClassTask extends IJobHandler {

    @Resource
    private ICourseClassService courseClassService ;



    @Override
    public ReturnT<String> execute(String... params) throws Exception {
        Example<CourseClass> courseClassExample=CourseClass.createExample();
        courseClassExample.createCriteria().andGreaterThan("startCourseTime", DateUtils.addYears(new Date(),-1));
        CourseClass courseClass=new CourseClass();
        courseClass.setUpdateTime(TimeUtils.now());
        courseClassService.updateSelectiveByExample(courseClass,courseClassExample);

        return ReturnT.SUCCESS ;

    }

}
